<template>
	<view style="background-color: white; height: 100vh;">
		<ot-table  @onClick='onclick'  textAlign="left" titleTextAlign="left" :tableData="tableData" :columns="tableColumns"
		 :stickSide="stickSideTable">
		</ot-table>
	</view>
</template>

<script>
	import {
		confirmModal,
		errorModal,
		getCharLength,
		getUrl
	} from '@/static/js/common.js';
	export default{
		data(){
			return {
				stickSideTable: false,//是否固定列
				tableData: [],
				tableColumns: [],
				url:''
			}
		},
		methods:{
			getName(wxColumn){
				if(wxColumn.nameChange){
					let newName = this.changeNames[wxColumn.name]
					if(newName){
						return newName;
					}else{
						return wxColumn.name;
					}
				}else{
					return wxColumn.name;
				}
			},
			wrapCol(item, o){
				let _that = this
				if(item.value.toString()){
					if(item.value.toString() === 'true'){
						o[item.field] = '√'
					}else if(item.value.toString() === 'false'){
						o[item.field] = ''
					}else{
						o[item.field] = item.value.toString()
					}
				}
			},
			loadTable(){
				let _that = this
				_that.om.request(
					_that.url
				).then(res=>{
					let objTable = {},objData = {},objColumns = {},objStickSideTable={};
						let showlist = res.value;
						if (showlist && showlist.length) {
							objTable = (this.subTableShowType == 0?false:true)  
							let data = []; //子表数据
							let column = []; //子表列标题
							let col = {} //
							for (let j = 0; j < showlist.length; j++) {
								let show = showlist[j];
								let o = {
									subTableIndex:j+1
								};
								if (show && show.length) {
									if (column.length == 0) {
										column.push({
											title:'序号',
											key: 'subTableIndex',
											width:90
										})
										for (let k = 0; k < show.length; k++) {
											let item = show[k]
											_that.wrapCol(item, o)
											let c = {
												title: _that.getName(item),//_that.changeTitles[item.name] ? _that.changeTitles[item.name] : item.name,
												key: item.field,
												width: Math.max(getCharLength(_that.getName(item)), getCharLength(item.value ? item.value.toString() : "")) * 12 +
													35
											}
											if(item.field == 'a' && item.tipUrl){
												c.url = item.tipUrl
												c.listenerClick = true
											}
											if(item.isfile){
												if(!item.multiFile && (item.fileName && item.fileName.endsWith("pdf")) ){
													c.isLink = {
														url: "/pages/public/pdf-preview/pdf-preview",
														params: ['url','busCode','fileId','fileUplaodKey']
													}
												}else{
													c.isLink = {
														url: "/pages/public/filetable/filetable",
														params: ['busCode','mainId','subId','simpleClazzName','url','fileId','fieldId','fileUplaodKey']
													}
												}
											}
											if(_that.busCode == 'DTM0201' && item.field == 'relationList'){
												c.isLink = {
													url: "/pages/form/ckd-zb-anytimereport/showRelationList",
													params:['showList']
												}
											}
											column.push(c)
											col[item.field] = c
										}
									} else {
										for (let k = 0; k < show.length; k++) {
											let item = show[k]
											_that.wrapCol(item, o)
											let width = getCharLength(item.value ? item.value.toString() : "") * 12 + 30
											if (!col[item.field] || !col[item.field].width) {} else {
												col[item.field].width = Math.max(col[item.field].width, (width>290?320:width+20))
											}
										}
									}
								}
								data.push(o)
							objData = data;
							objColumns= column;
							objStickSideTable=true
						}
					}
					_that.tableData = objData;
					_that.tableColumns = objColumns;
					_that.stickSideTable = objStickSideTable
				})
			}
		},
		onLoad(options) {
			let _that = this
			if(options.url){
				_that.url = options.url
			}
			_that.loadTable()
		}
	}
</script>

<style>
</style>